cmake_minimum_required(VERSION 3.16)
project(basic)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(CMAKE_CXX_COMPILE_FEATURES)
set(CMAKE_CXX_FLAGS "${CAMKE_CXX_FLAGS} -std=c++20 -pthread")

message(STATUS "platform: ${CMAKE_SYSTEM_NAME}")

# c codes
add_subdirectory("c_codes")
add_subdirectory("os")
add_subdirectory("cpp20_recipes")
# c++23 std
add_subdirectory("cppstd")


if (EXISTS /usr/local/bin/gcc)
    set(CMAKE_C_COMPILER "/usr/local/bin/gcc")
    set(CMAKE_CXX_COMPILER "/usr/local/bin/g++")
elseif(EXISTS /usr/bin/gcc)
    set(CMAKE_C_COMPILER "/usr/bin/gcc")
    set(CMAKE_CXX_COMPILER "/usr/bin/g++")
else()
    message(STATUS "没有编译器可用")
    return()
endif ()


if (UNIX AND NOT APPLE)
    # sudo apt-get install libmysql++-dev libmysqlclient-dev
    # sudo apt-get install libre2-dev

    message(STATUS "unix")

    include_directories(
            "/usr/include/mysql++"
            "/usr/include/mysql"
            "/usr/local/include/re2"
    )
    link_libraries("mysqlpp" "mysqlclient" "re2")
elseif (WIN32)
    message(STATUS "windows")

elseif (APPLE)
    message(STATUS "mac os")
    # 增加包含路径
    # mysql++, mysql, re2 为brew安装，在建立软连接到本地地址
    include_directories(
            "/usr/local/include/"
            "/usr/local/include/mysql++"
            "/usr/local/include/mysql"
            "/usr/local/include/re2"
    )
    # 库文件路径
    link_directories("/usr/local/lib/")
    link_libraries(
            "mysqlpp"
            "mysqlclient"
            "re2"
    )
else ()
    message(STATUS "other platform: ${CMAKE_SYSTEM_NAME}")
    return()
endif ()

IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    MESSAGE(STATUS "current platform: Linux ")
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
    MESSAGE(STATUS "current platform: MacOS Darwin")
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
    MESSAGE(STATUS "current platform: Windows")
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
    MESSAGE(STATUS "current platform: FreeBSD")
ELSE ()
    MESSAGE(STATUS "other platform: ${CMAKE_SYSTEM_NAME}")
ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux")

#crtp 用例
add_executable(crtp parttern_crtp.cpp parttern_crtp.h)
# 目标文件编译参数
add_executable(
        basic
        main.cpp
        func.h func.cpp
        DbQuery.h DbQuery.cpp
        Obj.cpp Obj.h
        llvm/compiler.h llvm/compiler.cpp
        sockets.cpp sockets.h
        grammars.cpp grammars.h
        CopyElision.cpp CopyElision.h
        stl_algorithm.cpp stl_algorithm.h
        file_handlers.h file_handlers.cpp
        String.cpp String.h
        class_invariant.cpp class_invariant.h
        Vector.cpp Vector.h
        exception.cpp exception.h
        scope.cpp scope.h
        smart_pointers.cpp smart_pointers.h
        concepts.cpp concepts.h
        include.h
        stl_tuple.cpp stl_tuple.h
        stl_tuple_iteration.cpp
        stl_tuple_iteration.h
        stl_polymorphic_transform.cpp stl_polymorphic_transform.h
        gramma_constexpr.cpp gramma_constexpr.h
        regex_re2.h regex_re2.cpp
        meta_programs.cpp meta_programs.h
)
